#include "EbnReceptor.h"
#include "EbnCondition.h"
#include "EbnWorldState.h"
#include "EbnReception.h"


CEbnReceptor::CEbnReceptor(CEbnWorldState * worldState)
{
    mpReception = new CEbnReception(worldState);
}

CEbnReceptor::~CEbnReceptor(void)
{
    mFromLinkList.clear();

    if (mpReception)
    {
        delete mpReception;
        mpReception = NULL;
    }
}

CEbnReception * CEbnReceptor::getReception(void)
{
    return mpReception;
}

bool CEbnReceptor::hasFromLink(CEbnLink * pLink)
{
    vector<CEbnLink *>::iterator itLink;
    for (itLink = mFromLinkList.begin(); itLink != mFromLinkList.end(); itLink++)
    {
        if ((*itLink) == pLink)
        {
            return true;
        }
    }

    return false;
}

void CEbnReceptor::addFromLink(CEbnLink * pLink)
{
    bool exist = hasFromLink(pLink);

    if (exist == false)
    {
        mFromLinkList.push_back(pLink);
    }
}

int CEbnReceptor::getFromLinkCount(void)
{
    return (int)mFromLinkList.size();
}

CEbnLink * CEbnReceptor::getFromLink(int index)
{
    if ((index < 1) || (index > getFromLinkCount()))
    {
        return NULL;
    }

    return mFromLinkList.at(index - 1);
}

bool CEbnReceptor::hasWorldState(CEbnWorldState * worldState)
{
    if (worldState == mpReception->getWorldState())
    {
        return true;
    }

    return false;
}
